﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BLL;

namespace GMS
{
    public partial class Pages_Admin_UserEstimates : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!SessionVariable.Instance.UserDetails.IsAdmin)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    gvUserOrder.DataSource = Common.GetUserOrder();
                    gvUserOrder.DataBind();
                }
            }
        }

        protected void gvUserOrder_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblUserId = (Label)e.Row.FindControl("lblid");

                if (lblUserId != null)
                {
                    List<DAL.GetUserShapeDimensionsResult> usdr = Common.GetUserShapeDimensionsByUserId(Convert.ToInt32(lblUserId.Text));

                    if (usdr != null && usdr.Count > 0)
                    {
                        int rowCount = 0;

                        foreach (DAL.GetUserShapeDimensionsResult item in usdr)
                        {
                            if (rowCount == 0)
                            {
                                Label lblShapeName = new Label();
                                Label lblShapeDescription = new Label();
                                Image imgShapeThumbnail = new Image();
                                Image imgShapeImagePath = new Image();

                                lblShapeName.Text = "ShapeName: " + item.ShapeName;
                                lblShapeDescription.Text = "ShapeDescription: " + item.ShapeDescription;

                                imgShapeThumbnail.ImageUrl = item.ShapeThumbnail;
                                imgShapeThumbnail.AlternateText = item.ShapeThumbnail;
                                imgShapeThumbnail.ToolTip = item.ShapeThumbnail;
                                imgShapeThumbnail.Height = Unit.Pixel(50);
                                imgShapeThumbnail.Width = Unit.Pixel(50);

                                imgShapeImagePath.ImageUrl = item.ShapeImagePath;
                                imgShapeImagePath.AlternateText = item.ShapeImagePath;
                                imgShapeImagePath.ToolTip = item.ShapeImagePath;
                                imgShapeImagePath.Height = Unit.Pixel(50);
                                imgShapeImagePath.Width = Unit.Pixel(50);

                                e.Row.Cells[31].Controls.Add(lblShapeName);
                                e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                                e.Row.Cells[31].Controls.Add(lblShapeDescription);
                                e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                                e.Row.Cells[31].Controls.Add(lblShapeDescription);
                                e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                                e.Row.Cells[31].Controls.Add(imgShapeImagePath);
                            }

                            Label lblSide = new Label();
                            Label lblSideTypeName = new Label();
                            Label lblSideTypeDescription = new Label();
                            Image imgSideTypeImagePath = new Image();
                            Label lblMeasurement = new Label();
                            Label lblIsBackSplash = new Label();

                            lblSide.Text = "Side: " + item.Side;
                            lblSideTypeName.Text = "SideTypeName: " + item.SideTypeName;
                            lblSideTypeDescription.Text = "SideTypeDescription: " + item.SideTypeDescription;

                            imgSideTypeImagePath.ImageUrl = item.SideTypeImagePath;
                            imgSideTypeImagePath.AlternateText = item.SideTypeImagePath;
                            imgSideTypeImagePath.ToolTip = item.SideTypeImagePath;
                            imgSideTypeImagePath.Height = Unit.Pixel(50);
                            imgSideTypeImagePath.Width = Unit.Pixel(50);

                            lblMeasurement.Text = "Measurement: " + Convert.ToString(item.Measurement);
                            lblIsBackSplash.Text = "IsBacklSplash: " + Convert.ToString(item.IsBackSplash);

                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(lblSide);
                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(lblSideTypeName);
                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(lblSideTypeDescription);
                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(imgSideTypeImagePath);
                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(lblMeasurement);
                            e.Row.Cells[31].Controls.Add(new HtmlGenericControl("br"));
                            e.Row.Cells[31].Controls.Add(lblIsBackSplash);

                            rowCount++;
                        }
                    }
                }
            }
        }
    }
}